home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_11 / 2n11012a < prev    next >
Text File  |  1991-09-08  |  2KB  |  101 lines

  1. #include        <stdio.h>
  2. #include        "memory.hpp"
  3.  
  4.  
  5. main()
  6. {
  7.  
  8.     unsigned **jj;
  9.     unsigned i,k;
  10.     unsigned sz;
  11.  
  12.     while (1)
  13.         {
  14.             printf ("Enter default size, no of items");
  15.             scanf("%d %d",&sz,&k);
  16.  
  17.             InitMem(sz);
  18.  
  19.             jj = new unsigned *[k];
  20.  
  21.             for (i=0;i<k;i++)
  22.                 {
  23.                     jj[i] = new unsigned;
  24.                 }
  25.  
  26.             for (i=0; i<k; i++)
  27.                 {
  28.                     if (jj[i] != NULL)
  29.                         *(jj[i]) = i;
  30.                 }
  31.  
  32.             for (i=0; i<k; i++)
  33.                 {
  34.                     if (jj[i] != NULL)
  35.         printf("value = %d pointer= %p long= %d\n",\
  36.                    *(jj[i]),jj[i],(long)(jj[i]) );
  37.                 }
  38.  
  39.             printf("pointer= %p long=%d\n",jj,(long)jj);
  40.  
  41.             float *f = new float;
  42.  
  43.             if (f != NULL)
  44.                 *f = 123456.7890;
  45.  
  46.     printf("old pointer=%p, new pointer=%p, new value=%f\n",\
  47.                             jj[2],f,*f);
  48.  
  49.             delete f;
  50.             f = NULL;
  51.  
  52.             for (i=0;i<k;i++)
  53.                 {
  54.                     delete jj[i];
  55.                     jj[i] = NULL;
  56.                 }
  57.  
  58.             delete jj;
  59.             jj = NULL;
  60.  
  61.             delete f;
  62.             f = NULL;
  63.  
  64.             jj = new unsigned *[k];
  65.  
  66.             for (i=0;i<k;i++)
  67.                 {
  68.                     jj[i] = new unsigned;
  69.                 }
  70.  
  71.             for (i=0; i<k; i++)
  72.                 {
  73.                     if (jj[i] != NULL)
  74.                         *(jj[i]) = i;
  75.                 }
  76.  
  77.             for (i=0; i<k; i++)
  78.                 {
  79.                     if (jj[i] != NULL)
  80.         printf("value = %d pointer= %p long= %d\n",\
  81.             *(jj[i]),jj[i],(long)(jj[i]) );
  82.                 }
  83.  
  84.         printf("pointer= %p long=%d\n", jj, (long)jj);
  85.  
  86.             for (i=0;i<k;i++)
  87.                 {
  88.                     delete jj[i];
  89.                     jj[i] = NULL;
  90.                 }
  91.  
  92.             delete jj;
  93.             jj = NULL;
  94.  
  95.  
  96.             EndMem();
  97.         }
  98. }
  99.  
  100.  
  101.